﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;

namespace OPMS_V1.DOL
{
    public class ListProperties
    {
        //Reffering to the LINQ Class
        S_PDataContext dc = new S_PDataContext();
        //This is the connection string for the database located at the localhost
        private const String connString = "server=localhost;database=OPMS;Integrated Security=SSPI";

        //Creating the SQLConnection using Connection String
        SqlConnection conn = new SqlConnection(connString);
        SqlDataReader reader = null;

        public DataSet GetDataSource()
        {
            DataSet ds = new DataSet();

            //Getting the session of the user using HttpContext.current.Session["xxx"]
            string LoginID = HttpContext.Current.Session["user"].ToString();

            //Collecting all the information into one datatable
            DataTable dtcomplete = new DataTable();
            DataRow drcomplete;

            //Adding the columns in datatable (Address, status, ID, Type) 
            //Used for displaying the fields on the Grid View
            dtcomplete.Columns.Add(new DataColumn("Property Address", typeof(string)));
            dtcomplete.Columns.Add(new DataColumn("Status", typeof(string)));
            dtcomplete.Columns.Add(new DataColumn("Property ID", typeof(string)));
            dtcomplete.Columns.Add(new DataColumn("Type", typeof(string)));

            #region This part will result in all the completed property Ads of the particular User
            //Executing the LINQ and storing it into HomeDetails
            var HomeDetails = dc.Manage_Home_Details(@LoginID);

            //Getting through all the records and binding in the grid view
            foreach (var Home in HomeDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string HomeType = null;

                //Getting the property Address
                PropertyAddress = Home.streetName.ToString() + ", " + Home.area.ToString() + ", " + Home.postalCode.ToString() + "\n"
                    + ", " + Home.state.ToString();
                //Getting the status of the Home
                Status = Home.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = Home.propertyID.ToString();
                //Getting the Type of Home Details
                HomeType = Home.Type.ToString();

                //Adding up the new row to the datarow
                drcomplete = dtcomplete.NewRow();
                //Passing all the values to the datarow
                drcomplete[0] = PropertyAddress;
                drcomplete[1] = Status;
                drcomplete[2] = PropertyID;
                drcomplete[3] = HomeType;

                //Adding the datarow to the datatable
                dtcomplete.Rows.Add(drcomplete);
            }

            //Executing the LINQ and storing it into LandDetails
            var LandDetails = dc.Manage_Land_Details(@LoginID);

            //Getting through all the records and binding in the grid view
            foreach (var Land in LandDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string LandType = null;

                //Getting the property Address
                PropertyAddress = Land.streetName.ToString() + ", " + Land.area.ToString() + ", " + Land.postalCode.ToString() + "\n"
                    + ", " + Land.state.ToString();

                //Getting the status of the Home
                Status = Land.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = Land.propertyID.ToString();
                //Getting the Type of Home Details
                LandType = Land.Type.ToString();

                //Adding up the new row to the datarow
                drcomplete = dtcomplete.NewRow();

                //Fill the datarow with the required information
                drcomplete[0] = PropertyAddress;
                drcomplete[1] = Status;
                drcomplete[2] = PropertyID;
                drcomplete[3] = LandType;

                //Adding all the rows to the dataTable
                dtcomplete.Rows.Add(drcomplete);
            }

            //Adding datatable to the dataset
            ds.Tables.Add(dtcomplete);

            #endregion This part will show all the completed property ads of the particular User

            //Return the dataset to the Grid View Page Index Changing
            return ds;
        }

        /// <summary>
        /// This function is used for returning the datasource for the Grid View
        /// It return the completed property Lists and then binds to the Grid View
        /// </summary>
        /// <returns></returns>
        public DataSet GetCompletedPropertyList()
        {
            //Getting the session of the user using HttpContext.current.Session["xxx"]
            string LoginID = HttpContext.Current.Session["user"].ToString();

            DataSet ds = new DataSet();
            //Collecting all the information into one datatable
            DataTable dtcomplete = new DataTable();
            DataRow drcomplete;

            //Adding the columns in datatable (Address, status, ID, Type)
            dtcomplete.Columns.Add(new DataColumn("Property Address", typeof(string)));
            dtcomplete.Columns.Add(new DataColumn("Status", typeof(string)));
            dtcomplete.Columns.Add(new DataColumn("Property ID", typeof(string)));
            dtcomplete.Columns.Add(new DataColumn("Type", typeof(string)));

            //This section is used for displaying the "completed" property ads to the Grid View

            #region This part will result in all the completed property Ads of the particular User
            //Executing the LINQ and storing it into HomeDetails
            var HomeDetails = dc.Manage_Home_Details(@LoginID);

            //Getting through all the records and binding in the grid view
            foreach (var Home in HomeDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string HomeType = null;

                //Getting the property Address
                PropertyAddress = Home.streetName.ToString() + ", " + Home.area.ToString() + ", " + Home.postalCode.ToString() + "\n"
                    + ", " + Home.state.ToString();
                //Getting the status of the Home
                Status = Home.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = Home.propertyID.ToString();
                //Getting the Type of Home Details
                HomeType = Home.Type.ToString();

                //Adding up the new row to the datarow
                drcomplete = dtcomplete.NewRow();
                //Passing all the values to the datarow
                drcomplete[0] = PropertyAddress;
                drcomplete[1] = Status;
                drcomplete[2] = PropertyID;
                drcomplete[3] = HomeType;

                //Adding the datarow to the datatable
                dtcomplete.Rows.Add(drcomplete);

                //Binding the grid view witrh the records present in datatable
            }

            //Executing the LINQ and storing it into LandDetails
            var LandDetails = dc.Manage_Land_Details(@LoginID);

            //Getting through all the records and binding in the grid view
            foreach (var Land in LandDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string LandType = null;

                //Getting the property Address
                PropertyAddress = Land.streetName.ToString() + ", " + Land.area.ToString() + ", " + Land.postalCode.ToString() + "\n"
                    + ", " + Land.state.ToString();

                //Getting the status of the Home
                Status = Land.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = Land.propertyID.ToString();
                //Getting the Type of Home Details
                LandType = Land.Type.ToString();

                //Adding up the new row to the datarow
                drcomplete = dtcomplete.NewRow();

                drcomplete[0] = PropertyAddress;
                drcomplete[1] = Status;
                drcomplete[2] = PropertyID;
                drcomplete[3] = LandType;

                dtcomplete.Rows.Add(drcomplete);
                //Binding the grid view witrh the records present in datatable
            }
            #endregion This part will show all the completed property ads of the particular User

            ds.Tables.Add(dtcomplete);
            
            //Return the dataset to the Grid View
            return ds;
        }

        /// <summary>
        /// This function is used for returning the datasource for the Grid View
        /// It return the completed property Lists and then binds to the Grid View
        /// </summary>
        /// <returns></returns>
        public DataSet ListCompletedPropertyList()
        {
            DataSet ds = new DataSet();
            //Collecting all the information into one datatable
            DataTable dtcomplete = new DataTable();
            DataRow drcomplete;

            //Adding the columns in datatable (Address, status, ID, Type)
            dtcomplete.Columns.Add(new DataColumn("Property Address", typeof(string)));
            dtcomplete.Columns.Add(new DataColumn("Status", typeof(string)));
            dtcomplete.Columns.Add(new DataColumn("Property ID", typeof(string)));
            dtcomplete.Columns.Add(new DataColumn("Type", typeof(string)));

            //This section is used for displaying the "completed" property ads to the Grid View

            #region This part will result in all the completed property Ads of the particular User
            //Executing the LINQ and storing it into HomeDetails
            var HomeDetails = dc.List_All_Home_Details();

            //Getting through all the records and binding in the grid view
            foreach (var Home in HomeDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string HomeType = null;

                //Getting the property Address
                PropertyAddress = Home.streetName.ToString() + ", " + Home.area.ToString() + ", " + Home.postalCode.ToString() + "\n"
                    + ", " + Home.state.ToString();
                //Getting the status of the Home
                Status = Home.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = Home.propertyID.ToString();
                //Getting the Type of Home Details
                HomeType = Home.Type.ToString();

                //Adding up the new row to the datarow
                drcomplete = dtcomplete.NewRow();
                //Passing all the values to the datarow
                drcomplete[0] = PropertyAddress;
                drcomplete[1] = Status;
                drcomplete[2] = PropertyID;
                drcomplete[3] = HomeType;

                //Adding the datarow to the datatable
                dtcomplete.Rows.Add(drcomplete);

                //Binding the grid view witrh the records present in datatable
            }

            //Executing the LINQ and storing it into LandDetails
            var LandDetails = dc.List_All_Land_Details();

            //Getting through all the records and binding in the grid view
            foreach (var Land in LandDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string LandType = null;

                //Getting the property Address
                PropertyAddress = Land.streetName.ToString() + ", " + Land.area.ToString() + ", " + Land.postalCode.ToString() + "\n"
                    + ", " + Land.state.ToString();

                //Getting the status of the Home
                Status = Land.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = Land.propertyID.ToString();
                //Getting the Type of Home Details
                LandType = Land.Type.ToString();

                //Adding up the new row to the datarow
                drcomplete = dtcomplete.NewRow();

                drcomplete[0] = PropertyAddress;
                drcomplete[1] = Status;
                drcomplete[2] = PropertyID;
                drcomplete[3] = LandType;

                dtcomplete.Rows.Add(drcomplete);
                //Binding the grid view witrh the records present in datatable
            }
            #endregion This part will show all the completed property ads of the particular User

            ds.Tables.Add(dtcomplete);

            //Return the dataset to the Grid View
            return ds;
        }

        /// <summary>
        /// This function is used for returning the datasource for the Grid View
        /// It return the completed property Lists and then binds to the Grid View
        /// </summary>
        /// <returns></returns>
        public DataSet GetIncompletedProperties()
        {
            DataSet ds = new DataSet();

            //Getting the session of the user using HttpContext.current.Session["xxx"]
            string LoginID = HttpContext.Current.Session["user"].ToString();

            DataTable dtincomplete = new DataTable();
            DataRow drincomplete;

            //Adding the columns in datatable (Address, status, ID, Type)
            dtincomplete.Columns.Add(new DataColumn("Property Address", typeof(string)));
            dtincomplete.Columns.Add(new DataColumn("Status", typeof(string)));
            dtincomplete.Columns.Add(new DataColumn("Property ID", typeof(string)));
            dtincomplete.Columns.Add(new DataColumn("Type", typeof(string)));
            //This section is used for displaying the "completed" property ads to the Grid View

            //This section is for displaying the incompleted property ads to the Grid View
            //Executing the LINQ and storing it into HomeDetails
            var IncompleteHomeDetails = dc.Manage_Home_Details_InComplete(@LoginID);

            #region This part will show all the "incompleted" property ads of the particular User
            //Getting through all the records and binding in the grid view
            foreach (var IncompleteHome in IncompleteHomeDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string HomeType = null;
                int counter = 0;
                counter++;

                //Getting the property Address
                PropertyAddress = IncompleteHome.streetName.ToString() + ", " + IncompleteHome.area.ToString() + ", " + IncompleteHome.postalCode.ToString() + "\n"
                    + ", " + IncompleteHome.state.ToString();
                //Getting the status of the Home
                Status = IncompleteHome.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = IncompleteHome.propertyID.ToString();
                //Getting the Type of Home Details
                HomeType = IncompleteHome.Type.ToString();

                //Adding up the new row to the datarow
                drincomplete = dtincomplete.NewRow();
                //Passing all the values to the datarow
                drincomplete[0] = PropertyAddress;
                drincomplete[1] = Status;
                drincomplete[2] = PropertyID;
                drincomplete[3] = HomeType;

                //Adding the datarow to the datatable
                dtincomplete.Rows.Add(drincomplete);
            }

            //Executing the LINQ and storing it into LandDetails
            var IncompleteLandDetails = dc.Manage_Land_Details_Incomplete(@LoginID);

            //Getting through all the records and binding in the grid view
            foreach (var IncompleteLand in IncompleteLandDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string LandType = null;

                //Getting the property Address
                PropertyAddress = IncompleteLand.streetName.ToString() + ", " + IncompleteLand.area.ToString() + ", " + IncompleteLand.postalCode.ToString() + "\n"
                    + ", " + IncompleteLand.state.ToString();

                //Getting the status of the Home
                Status = IncompleteLand.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = IncompleteLand.propertyID.ToString();
                //Getting the Type of Home Details
                LandType = IncompleteLand.Type.ToString();

                //Adding up the new row to the datarow
                drincomplete = dtincomplete.NewRow();

                drincomplete[0] = PropertyAddress;
                drincomplete[1] = Status;
                drincomplete[2] = PropertyID;
                drincomplete[3] = LandType;

                dtincomplete.Rows.Add(drincomplete);
            }
            #endregion This part will show all the "incompleted" property ads of the particular User

            ds.Tables.Add(dtincomplete);

            //Return the dataset to the Grid View
            return ds;
        }

        /// <summary>
        /// This function is used for returning the datasource for the Grid View
        /// It return the completed property Lists and then binds to the Grid View
        /// </summary>
        /// <returns></returns>
        public DataSet ListIncompletedProperties()
        {
            DataSet ds = new DataSet();

            //Getting the session of the user using HttpContext.current.Session["xxx"]
            string LoginID = HttpContext.Current.Session["user"].ToString();

            DataTable dtincomplete = new DataTable();
            DataRow drincomplete;

            //Adding the columns in datatable (Address, status, ID, Type)
            dtincomplete.Columns.Add(new DataColumn("Property Address", typeof(string)));
            dtincomplete.Columns.Add(new DataColumn("Status", typeof(string)));
            dtincomplete.Columns.Add(new DataColumn("Property ID", typeof(string)));
            dtincomplete.Columns.Add(new DataColumn("Type", typeof(string)));
            //This section is used for displaying the "completed" property ads to the Grid View

            //This section is for displaying the incompleted property ads to the Grid View
            //Executing the LINQ and storing it into HomeDetails
            var IncompleteHomeDetails = dc.ListAll_Home_Details_InComplete();

            #region This part will show all the "incompleted" property ads of the particular User
            //Getting through all the records and binding in the grid view
            foreach (var IncompleteHome in IncompleteHomeDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string HomeType = null;
                int counter = 0;
                counter++;

                //Getting the property Address
                PropertyAddress = IncompleteHome.streetName.ToString() + ", " + IncompleteHome.area.ToString() + ", " + IncompleteHome.postalCode.ToString() + "\n"
                    + ", " + IncompleteHome.state.ToString();
                //Getting the status of the Home
                Status = IncompleteHome.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = IncompleteHome.propertyID.ToString();
                //Getting the Type of Home Details
                HomeType = IncompleteHome.Type.ToString();

                //Adding up the new row to the datarow
                drincomplete = dtincomplete.NewRow();
                //Passing all the values to the datarow
                drincomplete[0] = PropertyAddress;
                drincomplete[1] = Status;
                drincomplete[2] = PropertyID;
                drincomplete[3] = HomeType;

                //Adding the datarow to the datatable
                dtincomplete.Rows.Add(drincomplete);
            }

            //Executing the LINQ and storing it into LandDetails
            var IncompleteLandDetails = dc.ListAll_Land_Details_Incomplete();

            //Getting through all the records and binding in the grid view
            foreach (var IncompleteLand in IncompleteLandDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string LandType = null;

                //Getting the property Address
                PropertyAddress = IncompleteLand.streetName.ToString() + ", " + IncompleteLand.area.ToString() + ", " + IncompleteLand.postalCode.ToString() + "\n"
                    + ", " + IncompleteLand.state.ToString();

                //Getting the status of the Home
                Status = IncompleteLand.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = IncompleteLand.propertyID.ToString();
                //Getting the Type of Home Details
                LandType = IncompleteLand.Type.ToString();

                //Adding up the new row to the datarow
                drincomplete = dtincomplete.NewRow();

                drincomplete[0] = PropertyAddress;
                drincomplete[1] = Status;
                drincomplete[2] = PropertyID;
                drincomplete[3] = LandType;

                dtincomplete.Rows.Add(drincomplete);
            }
            #endregion This part will show all the "incompleted" property ads of the particular User

            ds.Tables.Add(dtincomplete);

            //Return the dataset to the Grid View
            return ds;
        }


        /// <summary>
        /// This function is used for returning the datasource for the Grid View
        /// It return the completed property Lists and then binds to the Grid View
        /// </summary>
        /// <returns></returns>
        public DataSet GetIncompleteDataSource()
        {
            DataSet ds = new DataSet();

            //Getting the session of the user using HttpContext.current.Session["xxx"]
            string LoginID = HttpContext.Current.Session["user"].ToString();

            DataTable dtincomplete = new DataTable();
            DataRow drincomplete;

            //Adding the columns in datatable (Address, status, ID, Type)
            dtincomplete.Columns.Add(new DataColumn("Property Address", typeof(string)));
            dtincomplete.Columns.Add(new DataColumn("Status", typeof(string)));
            dtincomplete.Columns.Add(new DataColumn("Property ID", typeof(string)));
            dtincomplete.Columns.Add(new DataColumn("Type", typeof(string)));
            //This section is used for displaying the "completed" property ads to the Grid View

            //This section is for displaying the incompleted property ads to the Grid View
            //Executing the LINQ and storing it into HomeDetails
            var IncompleteHomeDetails = dc.Manage_Home_Details_InComplete(@LoginID);

            #region This part will show all the "incompleted" property ads of the particular User
            //Getting through all the records and binding in the grid view
            foreach (var IncompleteHome in IncompleteHomeDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string HomeType = null;
                int counter = 0;
                counter++;

                //Getting the property Address
                PropertyAddress = IncompleteHome.streetName.ToString() + ", " + IncompleteHome.area.ToString() + ", " + IncompleteHome.postalCode.ToString() + "\n"
                    + ", " + IncompleteHome.state.ToString();
                //Getting the status of the Home
                Status = IncompleteHome.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = IncompleteHome.propertyID.ToString();
                //Getting the Type of Home Details
                HomeType = IncompleteHome.Type.ToString();

                //Adding up the new row to the datarow
                drincomplete = dtincomplete.NewRow();
                //Passing all the values to the datarow
                drincomplete[0] = PropertyAddress;
                drincomplete[1] = Status;
                drincomplete[2] = PropertyID;
                drincomplete[3] = HomeType;

                //Adding the datarow to the datatable
                dtincomplete.Rows.Add(drincomplete);
            }

            //Executing the LINQ and storing it into LandDetails
            var IncompleteLandDetails = dc.Manage_Land_Details_Incomplete(@LoginID);

            //Getting through all the records and binding in the grid view
            foreach (var IncompleteLand in IncompleteLandDetails)
            {
                string PropertyAddress = null;
                string Status = null;
                string PropertyID = null;
                string LandType = null;

                //Getting the property Address
                PropertyAddress = IncompleteLand.streetName.ToString() + ", " + IncompleteLand.area.ToString() + ", " + IncompleteLand.postalCode.ToString() + "\n"
                    + ", " + IncompleteLand.state.ToString();

                //Getting the status of the Home
                Status = IncompleteLand.AdStatus.ToString();
                //Getting the Property ID of Home Details
                PropertyID = IncompleteLand.propertyID.ToString();
                //Getting the Type of Home Details
                LandType = IncompleteLand.Type.ToString();

                //Adding up the new row to the datarow
                drincomplete = dtincomplete.NewRow();

                drincomplete[0] = PropertyAddress;
                drincomplete[1] = Status;
                drincomplete[2] = PropertyID;
                drincomplete[3] = LandType;

                dtincomplete.Rows.Add(drincomplete);
            }
            #endregion This part will show all the "incompleted" property ads of the particular User

            ds.Tables.Add(dtincomplete);

            //Return the dataset to the Grid View
            return ds;
        }

        /// <summary>
        /// This function is used for Editing the home details
        /// It returns the List of Home Details with the Specific Property ID
        /// </summary>
        /// <param name="propID"></param>
        /// <returns></returns>
        public DataSet GetEditHomeDetails(string propID)
        {
            DataSet data = new DataSet();
            using (SqlCommand command = new SqlCommand("Get_Edit_HomeProperty_List", conn))
            {
                try
                {
                    //Open the SQL Connection
                    conn.Open();

                    //Run the command type as a stored procedure
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add("@Propertyid", SqlDbType.VarChar, 50).Value = propID;
                    //Execute the reader for retrieving the results from the database
                    //reader = command.ExecuteReader();

                    //If results forund the read the data
                    SqlDataAdapter da = new SqlDataAdapter(command);
                    //Filling the DataSet with the List of Area Information

                    da.Fill(data);
                }
                catch (SqlException)
                { return null; }
                finally
                {
                    //If the connection state is open then close the connection to the database.
                    if (conn.State == ConnectionState.Open)
                    {//Close the connection
                        conn.Close();
                    }
                }
            }
            return data;
        }


        /// <summary>
        /// This function is used for Editing the home details
        /// It returns the List of Home Details with the Specific Property ID
        /// </summary>
        /// <param name="propID"></param>
        /// <returns></returns>
        public DataSet GetEditLandDetails(string propID)
        {
            DataSet data = new DataSet();
            using (SqlCommand command = new SqlCommand("Get_Edit_LandProperty_List", conn))
            {
                try
                {
                    //Open the SQL Connection
                    conn.Open();

                    //Run the command type as a stored procedure
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add("@Propertyid", SqlDbType.VarChar, 50).Value = propID;
                    //Execute the reader for retrieving the results from the database
                    //reader = command.ExecuteReader();

                    //If results forund the read the data
                    SqlDataAdapter da = new SqlDataAdapter(command);
                    //Filling the DataSet with the List of Area Information

                    da.Fill(data);
                }
                catch (SqlException)
                { return null; }
                finally
                {
                    //If the connection state is open then close the connection to the database.
                    if (conn.State == ConnectionState.Open)
                    {//Close the connection
                        conn.Close();
                    }
                }
            }
            return data;
        }


        /// <summary>
        /// This function is used for returning the Area List on the basis of its AreaID
        /// </summary>
        /// <param name="AreaID"></param>
        /// <returns></returns>
        public DataSet GetArea(string AreaID)
        {
            DataSet data = new DataSet();
            using (SqlCommand command = new SqlCommand("Get_Area", conn))
            {
                try
                {
                    //Open the SQL Connection
                    conn.Open();

                    //Run the command type as a stored procedure
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add("@AreaID", SqlDbType.VarChar, 50).Value = AreaID;
                    //Execute the reader for retrieving the results from the database
                    //reader = command.ExecuteReader();

                    //If results forund the read the data
                    SqlDataAdapter da = new SqlDataAdapter(command);
                    //Filling the DataSet with the List of Area Information

                    da.Fill(data);
                }
                catch (SqlException)
                { return null; }
                finally
                {
                    //If the connection state is open then close the connection to the database.
                    if (conn.State == ConnectionState.Open)
                    {//Close the connection
                        conn.Close();
                    }
                }
            }
            return data;
        }


        /// <summary>
        /// This function is used for returning the Area List on the basis of its AreaID
        /// </summary>
        /// <param name="AreaID"></param>
        /// <returns></returns>
        public DataSet GetImages(string PropID)
        {
            DataSet data = new DataSet();
            using (SqlCommand command = new SqlCommand("Get_Images", conn))
            {
                try
                {
                    //Open the SQL Connection
                    conn.Open();

                    //Run the command type as a stored procedure
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add("@PropertyID", SqlDbType.VarChar, 50).Value = PropID;
                    //Execute the reader for retrieving the results from the database
                    //reader = command.ExecuteReader();

                    //If results forund the read the data
                    SqlDataAdapter da = new SqlDataAdapter(command);
                    //Filling the DataSet with the List of Area Information

                    da.Fill(data);
                }
                catch (SqlException)
                { return null; }
                finally
                {
                    //If the connection state is open then close the connection to the database.
                    if (conn.State == ConnectionState.Open)
                    {//Close the connection
                        conn.Close();
                    }
                }
            }
            return data;
        }
    }
}
